package org.gpp.proj1.robot.action.step;

import java.util.List;
import java.util.Set;

import org.gpp.proj1.robot.Robot;
import org.gpp.proj1.robot.part.EquippedPart;
import org.gpp.proj1.robot.part.emissor.Emissor;

import com.jme.scene.Node;

public class StopEmissionActionStep implements ActionStep {
	
	private String emissorName;
	
	public StopEmissionActionStep( String emissorName ) {
		this.emissorName = emissorName;
	}

	public void execute( EquippedPart part, List<Robot> targets ) {
		
		Emissor emissor = part.getEmissor( emissorName );
		Set<String> bones = part.getAssignedBoneGroupNames();

		// For each bone on the emissor parent list, attach it to the bone
		// and start the particle emission
		for( String boneName : bones ) {
			Node emissorNode = emissor.getEmissorNode( boneName );
			
			if( emissorNode != null ) {
				part.getParentRobot().removeEmissor( boneName, emissor );
				emissorNode.detachAllChildren();
			}
		}
	}
	
	public String getEmissorName() {
		return emissorName;
	}
}